Declarations

KCL supports all kinds of declarations described in the Common Lisp Reference Manual. Any valid declaration will affect the KCL environment in some way or another, although information obtained by declarations, other than special declarations, is mainly used by the KCL compiler.


As described in the Common Lisp Reference Manual, Common Lisp declarations are divided into two classes: proclamations and others. A proclamation is a global declaration given by the function proclaim, the top-level macro defvar, or the top-level macro defparameter. Once given, a proclamation remains effective during the KCL session unless it is shadowed by a local declaration or is canceled by another proclamation. Any other declaration is a local declaration and is given only by the special form declare. A local declaration remains in effect only within the body of the construct that surrounds the declaration. In the following nonsensical example borrowed from Chapter 9 of the Common Lisp Reference Manual,

     (defun nonsense (k x z)
        (foo z x)
        (let ((j (foo k x))
              (x (* k k)))
             (declare (inline foo) (special x z))
          (foo x j z)))

the inline and the special declarations both remain in effect within the surrounding let form. In this case, we say that the let form is the surrounding construct of these declarations.

proclamation decl-spec[Function]

This function is introduced to KCL so that the user can see currently effective proclamations. The argument decl-spec specifies the proclamation to be checked. It may be any declaration specification that can be a valid argument to the function proclaim. The function proclamation returns t if the specified proclamation is still in effect. Otherwise, it returns nil. For example,

>(proclaim '(special *x*))  ;;;  The variable  *x*  is 
nil                         ;;;  proclaimed to be globally special. 
 
>(proclamation '(special *x*))
t
 
>(defvar *y*)                ;;;  Another way to proclaim a variable 
nil                          ;;;  to be globally special. 
 
>(proclamation '(special *y*))
t

the value-type form[Special Form]

The KCL interpreter does actually check whether the value of the form conforms to the data type specified by value-type and signals an error if the value does not. The type checking is performed by the function typep. For example,

        (the fixnum (foo))

      is equivalent to

      (let ((values (multiple-value-list (foo))))
         (cond ((endp values) (error ``Too few return values.''))
               ((not (endp (cdr values)))
                (error ``Too many return values.''))
               ((typep (car values) 'fixnum) (car values))
               (t (error ``~s is not of type fixnum.'' (car values)))))

On the other hand, the KCL compiler uses the the special form to obtain type information for compiled code optimization. No code for runtime type-checking is embedded in the compiled code.



Subsections